import Vue from 'vue';
import Mint from 'mint-ui';
import App from "./App.vue";
import router from "./router";
import store from "./store/store";
import axios from './store/http'
import "./registerServiceWorker";
import "amfe-flexible"
// 图片预览 https://826327700.github.io/vue-photo-preview/
import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
var options={fullscreenEl:false} //关闭全屏按钮
Vue.use(preview,options)
import "mint-ui/lib/style.min.css"
import wechat from 'weixin-js-sdk'
import IScrollView from 'vue-iscroll-view'
//import IScroll from 'iscroll'
import IScroll from 'iscroll/build/iscroll-probe'
import config from './store/config'

import '@babel/polyfill'
import Es6Promise from 'es6-promise'
Es6Promise.polyfill()

//import IScroll from 'iscroll/build/iscroll-infinite.js'
// import IScroll from 'iscroll/build/iscroll-view.js'
// import IScroll from 'iscroll/build/iscroll-zoom.js'
// import IScroll from 'iscroll/build/iscroll-lite.js'

//import 'vue-googlemaps/dist/vue-googlemaps.css'
//import VueGoogleMaps from 'vue-googlemaps'
//Vue.use(VueGoogleMaps, {
//    load: {
//        //填入申请的apiKey账号
//        apiKey: 'AIzaSyBICWcSC4Iosl2raNVBEw7Qt3FmD28d8xE',
//        libraries: ['places'],
//        useBetaRenderer: false,
//        loadCn:true
//    },
//})

Vue.config.productionTip = false;

Vue.use(Mint);
Vue.use(IScrollView, IScroll)




Vue.prototype.axios = axios;

if(process.env.NODE_ENV == "development"){
  // 本地开发环境
  Vue.prototype.stripe_key = "pk_test_HcLF3AmiXYA9d899F0ariqUG";
}else{
  if(config.url.indexOf("c.kuaibangxing.com") < 0){
    //  测试开放
    Vue.prototype.stripe_key = "pk_test_HcLF3AmiXYA9d899F0ariqUG";
  }else{
    //生产开放
    Vue.prototype.stripe_key = "pk_live_8vtxdk6dcW2Sh3ovc97dC6tM";
  }
}

Vue.prototype.isWechat = false;
var browser = {
  versions: function () {
      var u = navigator.userAgent, app = navigator.appVersion;
      return {         //移动终端浏览器版本信息
          trident: u.indexOf('Trident') > -1, //IE内核
          presto: u.indexOf('Presto') > -1, //opera内核
          webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
          gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
          mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
          ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
          android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
          iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
          iPad: u.indexOf('iPad') > -1, //是否iPad
          webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
      };
  }(),
  language: (navigator.browserLanguage || navigator.language).toLowerCase()
}
if (browser.versions.mobile) {//判断是否是移动设备打开。browser代码在下面
  var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
  if (ua.match(/MicroMessenger/i) == "micromessenger") {
    //在微信中打开
    Vue.prototype.isWechat = true;

  }
  // if (browser.versions.ios) {
  //         //是否在IOS浏览器打开
  // } 
  // if(browser.versions.android){
  //         //是否在安卓浏览器打开
  // }


} else {
  //否则就是PC浏览器打开
}

function ready(fn) {
  if (document.readyState != 'loading') {
      fn();
  } else {
      document.addEventListener('DOMContentLoaded', fn);
  }
}
ready(function () {
  let el = document.createElement("script");
  el.src = "https://js.stripe.com/v3/";
  let s = document.getElementsByTagName("script")[1];
  // let el1= document.createElement("script");
  // el1.src="https://www.google.cn/maps/api/js?language=en&key=AIzaSyBICWcSC4Iosl2raNVBEw7Qt3FmD28d8xE"
  // s.parentNode.insertBefore(el1, s);

  if(Vue.prototype.isWechat){
      wechat.miniProgram.getEnv(function(res) {
          if(res.miniprogram){
            return;
          }
          console.log(res.miniprogram)
          s.parentNode.insertBefore(el, s);
      })
  }else{
      s.parentNode.insertBefore(el, s);
  }
  
})

//针对微信分享链接做一步前端redirect URL操作，防止串改url
if(location.href.split("#")[0].indexOf("isappinstalled=")>-1 || location.href.split("#")[0].indexOf("from=")>-1){
    let routerLink = location.href.split("#")[1];
    let url = location.href.split("#")[0].split("?")[0]+"#"+routerLink;
    window.location.href = url;
};

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
